package cn.stylefeng.guns.modular.emergency.controller;

import cn.stylefeng.guns.core.consts.ProjectConstants;
import cn.stylefeng.guns.modular.emergency.entity.EmergencyType;
import cn.stylefeng.guns.modular.emergency.pojo.request.EmergencyTypeRequest;
import cn.stylefeng.guns.modular.emergency.pojo.response.TreeEmergencyTypeInfo;
import cn.stylefeng.guns.modular.emergency.service.EmergencyTypeService;
import cn.stylefeng.guns.modular.emergency.service.TreeEmergencyTypeService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 应急预案分类表控制器
 *
 * @author xbz
 * @date 2023/04/24 14:58
 */
@RestController
@ApiResource(name = "应急预案分类表")
public class EmergencyTypeController {

    @Resource
    private EmergencyTypeService emergencyTypeService;

    @Resource
    private TreeEmergencyTypeService treeEmergencyTypeService;

    /**
     * 添加
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @PostResource(name = "添加", path = "/emergencyType/add",requiredPermission = false,requiredLogin = false)
    public ResponseData<EmergencyType> add(@RequestBody @Validated(EmergencyTypeRequest.add.class) EmergencyTypeRequest emergencyTypeRequest) {
        emergencyTypeService.add(emergencyTypeRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @PostResource(name = "删除", path = "/emergencyType/delete",requiredPermission = false,requiredLogin = false)
    public ResponseData<?> delete(@RequestBody @Validated(EmergencyTypeRequest.delete.class) EmergencyTypeRequest emergencyTypeRequest) {
        emergencyTypeService.del(emergencyTypeRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @PostResource(name = "编辑", path = "/emergencyType/edit",requiredPermission = false,requiredLogin = false)
    public ResponseData<?> edit(@RequestBody @Validated(EmergencyTypeRequest.edit.class) EmergencyTypeRequest emergencyTypeRequest) {
        emergencyTypeService.edit(emergencyTypeRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @GetResource(name = "查看详情", path = "/emergencyType/detail",requiredPermission = false,requiredLogin = false)
    public ResponseData<EmergencyType> detail(@Validated(EmergencyTypeRequest.detail.class) EmergencyTypeRequest emergencyTypeRequest) {
        return new SuccessResponseData<>(emergencyTypeService.detail(emergencyTypeRequest));
    }

    /**
     * 获取列表
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @GetResource(name = "获取列表", path = "/emergencyType/list",requiredPermission = false,requiredLogin = false)
    public ResponseData<List<EmergencyType>> list(EmergencyTypeRequest emergencyTypeRequest) {
        return new SuccessResponseData<>(emergencyTypeService.findList(emergencyTypeRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author xbz
     * @date 2023/04/24 14:58
     */
    @GetResource(name = "分页查询", path = "/emergencyType/page",requiredPermission = false,requiredLogin = false)
    public ResponseData<PageResult<EmergencyType>> page(EmergencyTypeRequest emergencyTypeRequest) {
        return new SuccessResponseData<>(emergencyTypeService.findPage(emergencyTypeRequest));
    }

    @GetResource(name = "获取应急预案分类树", path = "/emergencyType/getTreeTypeList",requiredPermission = false,requiredLogin = false)
    public ResponseData<List<TreeEmergencyTypeInfo>> getTreeTypeList(){
        String tableName = ProjectConstants.EPC_EMERGENCY_TYPE_TABLE_NAME;
        return new SuccessResponseData<>(treeEmergencyTypeService.getTreeTypeList(tableName));
    }

    @GetResource(name = "获取分类叶子节点", path = "/emergencyType/getLeafNodeList",requiredPermission = false,requiredLogin = false)
    public ResponseData<List<TreeEmergencyTypeInfo>> getLeafNodeList(){
        String tableName = ProjectConstants.EPC_EMERGENCY_TYPE_TABLE_NAME;
        return new SuccessResponseData<>(treeEmergencyTypeService.getLeafNodeList(tableName));
    }
}
